package zhengzei;

import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
   正则对象
   查找:

   指定为字符串的正则表达式必须首先被编译为此类的实例。然后,可将得到的正则
   对象匹配任意的字符串用于创建Matcher对象,执行匹配所涉及的所有状态都驻留
   在匹配容器中,所以多个匹配器可以共享同一模式。因此,典型的调用顺序是
      Pattern p = Pattern.compile("\\d{9}");
      Matcher m = p.matcher("aaaaa1233);
      boolean b = m.matches();

   查找需要使用的对象:
      1. Pattern(正则对象)
      2. Matcher(匹配器对象)

   匹配器要使用到的方法:
      1.find() 通知匹配器去匹配字符串,查找符合规则的字符串。如果能查找到符合规则的
      字符串,则返回true,否则返回false。
      2.group() 获取符合规则的子串

   注意:使用group方法的时一定要先调用find方法

   注意: 使用group方法的时候一定要先调用find方法让匹配器去查找符合规则的字符串,否则报错。
 */
public class ZhengZeTest {


    /*
        找出三个字母组成的单词
     */
    public static void test1(){
        String content = "da jia de jia qi wan bi liao hai hai xin ma aaaaa";
        String reg="\\b[a-zA-Z]{3}\\b";
        //使用了单词边界符
        Pattern p = Pattern.compile(reg);
        //先把要字符串的正则编译成Pattern对象。
        Matcher m = p.matcher(content);
        //使用正则对象匹配字符串用于产生一个Matcher对象

        while(m.find()){
            System.out.println(m.group());
        }

    }

    @Test
    public void test2(){
        String portCode = "AAAAA";
        if (! portCode.matches("[A-Z]{3}|[A-Z]{5}")) {
            System.out.println("非法");
        }

    }

    @Test
    public void test3(){
        String mail = "dffdfdf@qq.com";
        if (! mail.matches("\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*")) {
            System.out.println("非法");
        }

    }

    @Test
    public void test4(){
        System.out.println("        ".matches("^\\s*$"));// 要么是空字符:"" 要么全是空白字符
    }

    @Test
    public void test5(){
        Pattern pattern = Pattern.compile("[^\\s]{1,}"); //[^\s]代表非空白符,出现在哪里都可以
        Matcher matcher = pattern.matcher("  a    ");
        boolean result = matcher.find();
        System.out.println(result);
    }

    @Test
    public void test6(){
        System.out.println("0060122121v".matches("00601.*"));
    }

    @Test
    public void test7(){
        System.out.println("FK18111".matches("^\\s*(F|f)\\s*(K|k)\\s*([1-1]\\s*[7-9]\\s*|\\s*[2-2]\\s*[0-1]).*$"));
    }

    /**
     * 营业执照号码的英文只能输入大写
     * Pattern.matches(regex, str)是全局匹配的
     */
    @Test
    public void test8(){
        // 营业执照号码的英文只能输入大写
        String regex = ".*[a-z]+.*";
        if(Pattern.compile(regex).matcher("1233@#1111z").matches()){
            System.out.println("营业执照号码的英文只能输入大写");
        }
    }

    /**
     * 正则取反
     * 如果当中有不包含 hello 就通过,否则预警
     * ^((?!你的正则表达式).)*
     */
    @Test
    public void test9(){
        String content = "AAb123";
        boolean result = Pattern.matches("((?!(a|A)(b|B)).)*", content);
        System.out.println(result);
    }

    @Test
    public void test10(){
        String regex = "^001.*$|^911.*$";
        System.out.println(Pattern.matches(regex, "002123"));
    }

    /**
     * Pattern 类是线程安全的
     */
    @Test
    public void test11(){
        String regex = "112";
        System.out.println(Pattern.matches(regex, "112"));
    }

    /**
     * 取反的正则表达式:
     * ^((?!你的正则表达式).)*
     * ab不能连着
     */
    @Test
    public void test12(){
        boolean matches = Pattern.matches("((?!(ab)).)*", "a1bab");
        System.out.println(matches);
    }

    /**
     * "." 圆点在中括号内部："." 圆点字符表示这个字符本身
     */
    @Test
    public void test13(){
        boolean matches = Pattern.matches("^[.]{4,200}$", "....");
        System.out.println(matches);
    }

    /**
     * 不允许出现任何1个中文字符
     */
    @Test
    public void test14(){
        boolean matches = Pattern.matches("[\\u4e00-\\u9fa5]*", "我");
        System.out.println(matches);
    }

    @Test
    public void test15(){
        boolean matches = Pattern.matches("((?!(à|â|ä|è|é|ê|ë|î|ï|ô|œ|ù|û|ü|ÿ|ç|À|Â|Ä|È|É|Ê|Ë|Î|Ï|Ô|Œ|Ù|Û|Ü|Ÿ|Ç|Æ|æ|Ā|ā|Ă|ă|Ą|ą|Ć|ć|Ĉ|ĉ|Ċ|ċ|Č|č|Ď|ď|Đ|đ|Ē|ē|Ĕ|ĕ|Ė|ė|Ę|ę|Ě|ě|Ĝ|ĝ|Ğ|ğ|Ġ|ġ|Ģ|ģ|Ĥ|ĥ|Ħ|ħ|Ĩ|ĩ|Ī|ī|Ĭ|ĭ|Į|į|İ|ı|Ĳ|ĳ|Ĵ|ĵ|Ķ|ķ|ĸ|Ĺ|ĺ|Ļ|ļ|Ľ|ľ|Ŀ|ŀ|Ł|ł|Ń|ń|Ņ|ņ|Ň|ň|ŉ|Ŋ|ŋ|Ō|ō|Ŏ|ŏ|Ő|ő|Œ|œ|Ŕ|ŕ|Ŗ|ŗ|Ř|ř|Ś|ś|Ŝ|ŝ|Ş|ş|Š|š|Ţ|ţ|Ť|ť|Ŧ|ŧ|Ũ|ũ|Ū|ū|Ŭ|ŭ|Ů|ů|Ű|ű|Ų|ų|Ŵ|ŵ|Ŷ|ŷ|Ÿ|Ź|ź|Ż|ż|Ž|ž|ſ|ƀ|Ɓ|Ƃ|ƃ|Ƅ|ƅ|Ɔ|Ƈ|ƈ|Ɖ|Ɗ|Ƌ|ƌ|ƍ|Ǝ|Ə|Ɛ|Ƒ|ƒ|Ɠ|Ɣ|ƕ|Ɩ|Ɨ|Ƙ|ƙ|ƚ|ƛ|Ɯ|Ɲ|ƞ|Ɵ|Ơ|ơ|Ƣ|ƣ|Ƥ|ƥ|Ʀ|Ƨ|ƨ|Ʃ|ƪ|ƫ|Ƭ|ƭ|Ʈ|Ư|ư|Ʊ|Ʋ|Ƴ|ƴ|Ƶ|ƶ|Ʒ|Ƹ|ƹ|ƺ|ƻ|Ƽ|ƽ|ƾ|ƿ|ǀ|ǁ|ǂ|ǃ|Ǆ|ǅ|ǆ|Ǉ|ǈ|ǉ|Ǌ|ǋ|ǌ|Ǎ|ǎ|Ǐ|ǐ|Ǒ|ǒ|Ǔ|ǔ|Ǖ|ǖ|Ǘ|ǘ|Ǚ|ǚ|Ǜ|ǜ|ǝ|Ǟ|ǟ|Ǡ|ǡ|Ǣ|ǣ|Ǥ|ǥ|Ǧ|ǧ|Ǩ|ǩ|Ǫ|ǫ|Ǭ|ǭ|Ǯ|ǯ|ǰ|Ǳ|ǲ|ǳ|Ǵ|ǵ|Ƕ|Ƿ|Ǹ|Ǻ|ǻ|Ǽ|ǽ|Ǿ|ǿ|Ȁ|ȁ|Ȃ|ȃ|Ȅ|ȅ|Ȇ|ȇ|Ȉ|ȉ|Ȋ|ȋ|Ȍ|ȍ|Ȏ|ȏ|Ȑ|ȑ|Ȓ|ȓ|Ȕ|ȕ|Ȗ|ȗ|Ș|ș|Ț|ț|Ȝ|ȝ|Ȟ|ȟ|Ƞ|ȡ|Ȣ|ȣ)).)*", "a1baîb");
        System.out.println(matches);
    }




    @Test
    public void test20(){
        boolean matches = Pattern.matches("1[\\w|\\W]*?5", "12345");
        System.out.println(matches);
    }

    @Test
    public void test21(){
        boolean matches = "19999".matches("^([1]\\d{4}(\\.\\d{1,4})?)|([1-9]\\d{3}(\\.\\d{1,4})?)|([1-9]\\d{2}(\\.\\d{1,4})?)|([1-9]\\d{1}(\\.\\d{1,4})?)|([0-9](\\.\\d{1,4})?)|20000(\\.0{1,4})?$");
        System.out.println(matches);
    }


    @Test
    public void test22(){
        final String regex="^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        final String email="wadwadawdwadassfdefekgkelalwldlwallwla@vip.qq.com#";
        boolean matches = email.matches(regex);
        System.out.println(matches);
    }



    public void show(String a){
        if(a == null){
            System.out.println(a.substring(0 ,11));
        }
    }




    public static void main(String[] args) {
        //test();
        test02();
    }

    public static void test02(){
        StringBuilder result = new StringBuilder();
        String content="àâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇÆæĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıĲĳĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňŉŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃǄǅǆǇǈǉǊǋǌǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰǱǲǳǴǵǶǷǸǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȡȢȣ";
        String[] split = content.split("");
        for (int i = 0; i <split.length; i++) {
            result.append(split[i]).append("|");
        }
        String substring = result.substring(0, result.length() - 1);
        System.out.println(substring);
    }



    public static void test(){
        String str="ES10024479908490001010001C0N\tRobert S Jersak\n" +
                "ES10024930970950001010001E0N\tAsset Enterprises Inc \n" +
                "ES10024957016580001010001B0N\tMiguel A Naves\n" +
                "ES10024964916580001010001G0N\tFRANKLIN E MARTIN F \n" +
                "ES10024965961990001010001C0N\tThomas E Brewer Jr \n" +
                "ES10024970395010001010001C0N\tGRAGO Jorleny Ruiz\n" +
                "ES10024975935490001010001G0N\tAmad Logistics ISH SA DE CV\n" +
                "ES10024975958210001010001B0N\tCari Med Group Limited Group\n" +
                "ES10024978392600001010001C0N\tWilliam D Degner\n" +
                "ES10024979045640001010001D0N\tDr Frank M Howell\n" +
                "ES10024980109820001010001A0N\tGary St Hilaire\n" +
                "ES10024980529280001010001E0N\tGreg R Apple\n" +
                "ES10024986024280001010001G0N\tSpecial T Mfg \n" +
                "ES10024986457920001010001F0N\tDeborah K Decker\n" +
                "ES10024986895200001010001E0N\tBeth A Sheehan\n" +
                "ES10024987223590001010001E0N\tEy Shawn Brandon\n" +
                "ES10024989586900001010001F0N\tPhilip Hield c o watermakers\n" +
                "ES10024989834430001010001G0N\tClemente M Guingguing Jr\n" +
                "ES10024989838140001010001E0N\tEID Group LLC LB\n" +
                "ES10024990382340001010001A0N\tRhyan Miller C O Ron Wilmott\n" +
                "ES10024992349040001010001E0N\tCompu Equipment Inc \n" +
                "ES10024993246420001010001E0N\tBryan C Miller\n" +
                "ES10024993340440001010001G0N\tPaul M Hall\n" +
                "ES10024995334500001010001C0N\tWilliam E Phelix\n" +
                "ES10024996673090001010001F0N\tLaura M Kantowski\n" +
                "ES10024998030980001010001C0N\tRonnie Mac s\n" +
                "ES10024999833150001010001G0N\tJohn R Barajas Jr \n" +
                "ES10025001512080001010001E0N\tGerald G Wilson Sr \n" +
                "ES10025002679350001010001C0N\tgianni alexander pedraza A\n" +
                "ES10025002683860001010001G0N\tpaul j cullings\n" +
                "ES10025003737810001010001G0N\tRicardo Trejos Gomez DUAL\n" +
                "ES10025004085840001010001C0N\tJames E Sykes\n" +
                "ES10025004110600001010001A0N\tJULIO A MARTINE OEC SEA \n" +
                "ES10025004116790001010001E0N\tCARTERSTYLE INC \n" +
                "ES10025004174430001010001E0N\tDeb S Tjelmeland\n" +
                "ES10025004174550001010001B0N\tDeb S Tjelmeland\n" +
                "ES10025004238550001010001G0N\tScott A Schiegg\n" +
                "ES10025004261280001010001G0N\tSTARWOOD POWERSPORTS PARTS DEPT \n" +
                "ES10025004494160001010001C0N\tDr Marcus Smith\n" +
                "ES10025005395250001010001A0N\tMarco Adorno c o Sara and Hunter\n" +
                "ES10025005566150001010001D0N\tS Stoetzer\n" +
                "ES10025005701110001010001B0N\tSUNTRACKSERVICES AIR Randy Thompson\n" +
                "ES10025006677430001010001A0N\tAnn Sofie Eklov\n" +
                "ES10025006997290001010001A0N\tGordon A Wells\n" +
                "ES10025007022960001010001F0N\tWillie E Murphey\n" +
                "ES10025007170900001010001B0N\tMichael Macblane Meyer\n" +
                "ES10025008341280001010001G0N\tSandy C Pleasant\n" +
                "ES10025009210380001010001C0N\tNancy O Donnell\n" +
                "ES10025009389840001010001C0N\tJavier Rodriguez  CRIS\n" +
                "ES10025009557050001010001B0N\tJames E Paulus\n" +
                "ES10025009558240001010001F0N\tErica M Towers\n" +
                "ES10025009941730001010001D0N\tGeorge C Miller\n" +
                "ES10025009946490001010001A0N\tVernon L Johnson Jr \n" +
                "ES10025011187940001010001E0N\teIS C O Shawn Williams\n" +
                "ES10025011481160001010001F0N\tF Valenz\n" +
                "ES10025014603910001010001A0N\tR Constantine\n" +
                "ES10025014705230001010001F0N\tKimberly Mulquin Shumway\n" +
                "ES10025014725650001010001B0N\tGabriel Ivan Serrano A \n" +
                "ES10025014933340001010001C0N\tEarl Dyck Rodney\n" +
                "ES10025015383480001010001C0N\tDiego Lainfiesta  luna gt\n" +
                "ES10025016377010001010001E0N\tMichael Maurin SXM \n" +
                "ES10025016876130001010001G0N\tDEWEY C  CROMARTIE JR \n" +
                "ES10025017088210001010001A0N\tJeffrey T Stevenson\n" +
                "ES10025017477250001010001D0N\tKord J Williams C O PRN\n" +
                "ES10025017529560001010001C0N\tMr Tower\n" +
                "ES10025017530390001010001A0N\tMarie Still Waldun\n" +
                "ES10025018405580001010001E0N\tJessica Miller Mr Key s\n" +
                "ES10025018796590001010001D0N\tJames E Paulus\n" +
                "ES10025018839630001010001G0N\tShanteria G \n" +
                "ES10025018850280001010001G0N\tOscar W Carley\n" +
                "ES10025018901300001010001G0N\tRobert Oliver Ressel\n" +
                "ES10025019116020001010001A0N\tJulio cesar Perez yanez\n" +
                "ES10025019410390001010001A0N\tBrian D LeClair\n" +
                "ES10025019417790001010001E0N\tKevin R Kidder\n" +
                "ES10025020066490001010001D0N\tAttitude Wellness  Receiving\n" +
                "ES10025021014500001010001C0N\tSteven P Reisman\n" +
                "ES10025021023890001010001F0N\tP A Hunley Sr \n" +
                "ES10025021056680001010001D0N\tTroy A Miller\n" +
                "ES10025021097690001010001C0N\tJose G Salazar\n" +
                "ES10025021290410001010001C0N\tF J Elliott\n" +
                "ES10025021603130001010001A0N\tFRANCISCO CASTILLO NOVA AEREO\n" +
                "ES10025021996400001010001C0N\tHawker  RT\n" +
                "ES10025022525690001010001B0N\tEli Snyder Jr\n" +
                "ES10025022657810001010001C0N\tLisa Scalia Maloney\n" +
                "ES10025022664450001010001A0N\tMiguel Rivera  Luis Cooper\n" +
                "ES10025023262300001010001C0N\tPatrick Murphy Racey\n" +
                "ES10025023304640001010001E0N\tRobert s Automotive Repairs\n" +
                "ES10025024169060001010001G0N\tJonathan P Rose\n" +
                "ES10025024241580001010001A0N\tBeverly Romero Kersh\n" +
                "ES10025024241840001010001D0N\tKolade H Ladjouan\n" +
                "ES10025025050140001010001F0N\tIbrahim A Fattah\n" +
                "ES10025026787450001010001E0N\tGary S Lukich Sr \n" +
                "ES10025027292100001010001A0N\tM Forrest\n" +
                "ES10025027667950001010001G0N\tRafael A Dorta Figueroa\n" +
                "ES10025028174200001010001B0N\tDana Bringas Flores\n" +
                "ES10025028339860001010001B0N\tBrian A Willoughby\n" +
                "ES10025028409610001010001E0N\tAero  Mauri Lopez\n" +
                "ES10025028453290001010001F0N\tEUGENE THOMPSON JR \n" +
                "ES10025028817400001010001B0N\tBrian J Troutman\n" +
                "ES10025029123740001010001F0N\tEvert Chang  AIR\n" +
                "ES10025029151240001010001G0N\tYong Sam Choi\n" +
                "ES10025029165940001010001D0N\tALEX RODRIGUEZ FEDERICO NARANJO\n" +
                "ES10025029199650001010001F0N\tChawynice E Clark\n" +
                "ES10025030140020001010001G0N\tBELAL MOUSA JORDAN AUTO SALES \n" +
                "ES10025030154600001010001A0N\tJason Lin  Greg Lawrence\n" +
                "ES10025030165220001010001B0N\tChristopher S Burchette\n" +
                "ES10025030196020001010001G0N\tDaniel R Kempton\n" +
                "ES10025030311430001010001E0N\tGary J Smith Jr \n" +
                "ES10025030343540001010001G0N\tBELAL MOUSA JORDAN AUTO SALES \n" +
                "ES10025030392650001010001F0N\tBrian K Rieck\n" +
                "ES10025030474580001010001C0N\tEd caesar zoon\n" +
                "ES10025030650930001010001B0N\tClifford D Felber\n" +
                "ES10025030695800001010001G0N\tPaul A Hunt\n" +
                "ES10025031229350001010001F0N\tJose M Vazquez\n" +
                "ES10025031254450001010001E0N\tCamilo Transtoria Logistic\n" +
                "ES10025031653100001010001F0N\tDonna hill wiley\n" +
                "ES10025031686640001010001E0N\tDavid A Merlino\n" +
                "ES10025032612980001010001E0N\tChristine Swanson Ushino\n" +
                "ES10025033162100001010001A0N\tMark a Lorey\n" +
                "ES10025033187660001010001A0N\tKike Lopez Miguelito\n" +
                "ES10025033263520001010001A0N\tEric E Vann\n" +
                "ES10025034602280001010001F0N\tSteven P Zuelzke";
        String[] split = str.split("\\n");
        for (String s : split) {
            String[] split1 = s.split("\\t");
            System.out.println(String.format("update t_waybill_consignee set modify_time = now(),modify_user_code = '181268',consignee_full_name = '%s' where tracking_number = '%s';",split1[1],split1[0]));
        }
    }



}
